/*
 * BanBu_PersonDataViewController
 * @description 本文件提供个人空间的viewController
 * @package
 * @author 		***
 * @copyright
 * @version 		1.0
 * @description 本文件提供个人空间的viewController
 */


#import "BanBu_PersonDataViewController.h"
#import "BanBu_BroadcastTVC.h"
#import "BanBu_PersonDataHeader.h"
#import "BanBu_ProfileDataController.h"
#import "AppDataManager.h"
#import "BanBu_PeopleDataController.h"
#import "BanBu_SnowFall.h"
#import "BanBu_LocationManager.h"
#import "BanBu_PeopleDataController.h"
#import "BanBu_NavButton.h"
#import "BanBu_FuncView.h"
#import "BanBu_ChatViewController.h"
#import "BanBu_Voice_ViewController.h"
#import "BanBu_PluginViewController.h"

#import "Profile.h"
#define FUNCTIONVIEW_HIDE CGRectMake(0, -80, 320, 80)
#define FUNCTIONVIEW_SHOW CGRectMake(0, 0, 320, 80)

@interface BanBu_PersonDataViewController ()
{
    BanBu_PersonDataHeader *headerView;
    BanBu_BroadcastTVC *broad;
    BanBu_ProfileDataController *profile;
    BanBu_PeopleDataController *peopleProfile;
    
    BanBu_FuncView  *moreFucView;
    UIView          *zhezhaoView;
    CGPoint currentOffset;
    
    BanBu_NavButton *moreActionBtn;
    
    //修改：yinlinlin
    BanBu_PersonAlbumDetailController * albumDetail;
    NSInteger _currentIndex;
    //修改完成：yinlinlin
    NSString * _user_id;
    
}
@end

@implementation BanBu_PersonDataViewController

@synthesize profileDic = _profileDic;

-(void)dealloc
{
    if([self isSelf])
    {
        [[NSNotificationCenter defaultCenter]removeObserver:self name:NOTIFICATION_REFRESH_PROFIL object:nil];
    }
    [AppComManager cancalHandlesForObject:self];
    [self.tableView removeFromSuperview];
    self.tableView = nil;
    self.profileDic = nil;
    [broad release],broad = nil;
    [profile release],profile = nil;
    
    self.tableView.tableHeaderView = nil;
    [headerView release],headerView = nil;
    [albumDetail release];
    albumDetail = nil;
    [_user_id release];
    _user_id = nil;
    [super dealloc];
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
-(void)viewWillAppear:(BOOL)animated
{
    //2014年09月28日17:45:08 by yinlinlin 修改个人空间下方的3个按钮
    if(peopleProfile)
    {
        [UIView animateWithDuration:0.5
                         animations:^{
                             CGRect rect = peopleProfile.toolbarView.frame;
                             rect.origin.y -= 64;
                             peopleProfile.toolbarView.frame = rect;
                         }];
    }
    
    
    [self.navigationController.navigationBar addSubview:_titleView];
    [self.navigationController.navigationBar addSubview:moreActionBtn];
    //修改：yinlinlin:2014/06/27:减少刷新，只有在修改的时候刷新
    if ((_currentIndex == 1) && ([albumDetail.refreStr isEqualToString:album_refresh]))
    {
        [albumDetail getPhotoAlbumList];
    }
    if([self isSelf])
    {
        NSDictionary * ufaceDict = [UserDefaults valueForKey:MyAppDataManager.useruid];
        [headerView.ufaceImage setImageWithURL:[NSURL URLWithString:[ufaceDict valueForKey:@"uface"]] placeholderImage:[UIImage imageNamed:@"default.png"] andType:1];
    }
}
-(void)viewWillDisappear:(BOOL)animated
{
     [self hideFunctionView];
    [_titleView removeFromSuperview];
    [moreActionBtn removeFromSuperview];
    //2014年09月28日17:45:08 by yinlinlin 修改个人空间下方的3个按钮
    if(peopleProfile)
    {
        [UIView animateWithDuration:0.5
                         animations:^{
                             CGRect rect = peopleProfile.toolbarView.frame;
                             rect.origin.y += 64;
                             peopleProfile.toolbarView.frame = rect;
                         }];
        
    }
}
- (id)initWithProfile:(NSDictionary *)_profile
{
    NSLog(@"上一界面传过来用户资料:%@",_profile);
    self = [super init];
    if (self)
    {
        _profileDic = [[NSMutableDictionary alloc] init];
        [_profileDic addEntriesFromDictionary:_profile];
        _user_id = [[_profile valueForKey:@"userid"] copy];
        
    }
    return self;
}

#pragma mark - 本人个人资料获取方法
/**
 *	@brief	本人个人资料获取方法
 */
-(void)getMyInfo
{
    [AppComManager getBanBuData:BanBu_Get_My_Info par:[NSDictionary dictionary] delegate:self];
    
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    
    headerView = [[BanBu_PersonDataHeader instanceView] retain];
    //暂时隐藏，每次都重新获取数据,解决数据显示不是最新的问题
    [headerView setDataSource:_profileDic];
    headerView.delegate = self;
    [self readyForLoadViewWithIndex:2];
    self.titleView = [BanBu_TitleView instanceView];
    self.titleView.center = CGPointMake(160, 22);
    [self.navigationController.navigationBar addSubview:self.titleView];
//    [self startGetMyPostitionInfo];
    currentOffset = CGPointMake(0, 0);
    
    if(![self isSelf])
    {
        //非本人个人资料获取方法
//        [self getPeopleInfo];
        [self getUserInfoExt];
    }
    else
    {
        [self buildMoreButton];
        //本人个人资料获取方法
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getMyInfo) name:NOTIFICATION_REFRESH_PROFIL object:nil];
        [self getMyInfo];
//        [self getUserInfoExt];
    }
    // Do any additional setup after loading the view from its nib.
 
    
}


#pragma mark - 非本人个人资料获取方法
/**
 * @函数名称：getUserInfoExt
 * @函数描述：
 * @输入参数：void
 * @输出参数：void
 * @返回值：void
 * @author：yinlinlin
 */
- (void)getUserInfoExt
{
    NSDictionary * parDict = [NSDictionary dictionaryWithObjectsAndKeys:[self getlastTimeWithUserId:_user_id],@"fromtime",_user_id,@"userid", nil];
    //获取用户的扩展资料
    [AppComManager getBanBuData:BanBu_Get_User_info_v2 par:parDict delegate:self];
}

#pragma mark - banbuRequestDidFinished
-(void)banbuRequestDidFinished:(NSDictionary *)resDic error:(NSError *)error
{
    //    NSLog(@"%@",resDic);
    if(error)
    {
        [TKLoadingView showTkloadingAddedTo:self.view title:NSLocalizedString(@"network_error", nil) activityAnimated:NO duration:1];
        
    }
    //获取自己的个人资料
    if([AppComManager respondsDic:resDic isFunctionData:BanBu_Get_My_Info])
    {
        NSLog(@"我自己的用户资料:%@",resDic);
        NSMutableDictionary *infoUpdata = [NSMutableDictionary dictionaryWithDictionary:[UserDefaults valueForKey:MyAppDataManager.useruid]];
        [infoUpdata addEntriesFromDictionary:resDic];
        [infoUpdata removeObjectsForKeys:[NSArray arrayWithObjects:@"ok",@"fc",nil]];
        [UserDefaults setValue:infoUpdata forKey:MyAppDataManager.useruid];
        [UserDefaults synchronize];
        //mz
        
        //更新新的数据
        [_profileDic removeAllObjects];
        [_profileDic addEntriesFromDictionary:infoUpdata];
        if ([_profileDic valueForKey:@"incityofname"])
        {
            [self updateTitleWithString:[_profileDic valueForKey:@"incityofname"]];
        }
        else
        {
            [self startGetMyPostitionInfo];
        }

        
        [headerView setDataSource:infoUpdata];
        if(profile) { [profile.tableView reloadData];};
        _titleView.name =  [MyAppDataManager IsInternationalLanguage:[MyAppDataManager theRevisedName:[_profileDic valueForKey:@"pname"] andUID:[_profileDic valueForKey:@"userid"]]];
        
    }
    //获取其他用户的个人资料
    else if([AppComManager respondsDic:resDic isFunctionData:BanBu_Get_User_info_v2])
    {
        NSLog(@"其他用户的个人资料:%@",resDic);
        if([[resDic valueForKey:@"ok"]boolValue])
        {
            //存储访问时间2014/07/10
            NSDictionary * dynamicDict = [BanBu_CommUtils getLocalData:DynamicKey];
            NSMutableDictionary * newdynamicDict = [NSMutableDictionary dictionaryWithDictionary:dynamicDict];
            NSDictionary * userDict = [NSDictionary dictionaryWithObjectsAndKeys:[resDic valueForKey:@"nowtime"],@"lasttime", nil];
            [newdynamicDict setValue:userDict forKey:_user_id];
            [BanBu_CommUtils setLocalData:newdynamicDict key:DynamicKey];
            
            //其他操作
            NSMutableDictionary *userInfor = [NSMutableDictionary dictionaryWithDictionary:resDic];
            [userInfor removeObjectForKey:@"fc"];
            [userInfor removeObjectForKey:@"actioncount"];
            NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:userInfor,keyPersonalInfo,[resDic valueForKey:@"userid"],@"userid",nil];
            
            __block NSMutableArray *saveArr = [[NSMutableArray alloc] initWithObjects:dic, nil];
            
            //向数据库存储个人信息，重新请求数据
            dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
            dispatch_async(queue, ^{
                [MyAppDataManager writePersonalDataToDB:saveArr];
                [saveArr release];
            });
            
            NSMutableDictionary  *parDic = [[NSMutableDictionary alloc] initWithDictionary:resDic];
            //            if([[parDic valueForKey:@"ltime"] rangeOfString:@"-"].location != NSNotFound)
            //            {
            //                [parDic setValue:[MyAppDataManager getTheLastOnlineTime:[parDic valueForKey:@"ltime"]] forKey:@"ltime"];
            //            }
            
            [_profileDic removeAllObjects];
            [_profileDic addEntriesFromDictionary:parDic];
            if (![[_profileDic valueForKey:@"incityofname"] isEqualToString:@""])
            {
                [self updateTitleWithString:[_profileDic valueForKey:@"incityofname"]];
            }
            else
            {
                [self getPosition];
            }
            [headerView setDataSource:_profileDic];
            [peopleProfile setProfile:_profileDic];
            if(peopleProfile)
            {
                [peopleProfile setProfile:_profileDic];
                [peopleProfile.tableView reloadData];
            }
            _titleView.name =  [MyAppDataManager IsInternationalLanguage:[MyAppDataManager theRevisedName:[_profileDic valueForKey:@"pname"] andUID:[_profileDic valueForKey:@"userid"]]];
        }
    }
    else if([[resDic valueForKey:@"fc"] isEqualToString:@"get_location"])
    {
        if([[resDic valueForKey:@"ok"] boolValue])
        {
            if([[[resDic valueForKey:@"result"]valueForKey:@"status"] isEqualToString:@"OK"])
            {
                if([[[resDic valueForKey:@"result"] valueForKey:@"results"] count] > 0)
                {
                    NSArray *results = [[[[resDic valueForKey:@"result"] valueForKey:@"results"] objectAtIndex:0] valueForKey:@"address_components"];
                    NSString *country = nil;
                    NSString *locality = nil;
                    
                    for(NSDictionary *dic in results)
                    {
                        NSString *type = [[dic valueForKey:@"types"] objectAtIndex:0];
                        
                        if(!country&&[type isEqualToString:@"country"])
                        {
                            country = [dic valueForKey:@"long_name"];
                        }
                        
                        if(!locality&&[type isEqualToString:@"administrative_area_level_1"])
                        {
                            locality = [dic valueForKey:@"long_name"];
                        }
                        
                        if(!locality&&[type isEqualToString:@"locality"])
                        {
                            locality = [dic valueForKey:@"long_name"];
                        }
                        
                    }
                    NSMutableString *result = [NSMutableString string];
                    
                    if(country) { [result appendString:country]; }
                    
                    if(locality){ [result appendFormat:@"-%@",locality]; }
                    
                    
                    [self updateTitleWithString:result];
                }
                else
                {
                    [self updateTitleWithString:NSLocalizedString(@"getLocationFail", nil)];
                }
            }
            else
            {
                [self updateTitleWithString:NSLocalizedString(@"getLocationFail", nil)];
                
            }
        }
        else
        {
            [self updateTitleWithString:NSLocalizedString(@"getLocationFail", nil)];
        }
    }
}


#pragma mark - 从本地获取上次看这个用户动态的时间
/**
 * @函数名称：getlastTimeWithUserId:
 * @函数描述：从本地获取上次看这个用户动态的时间
 * @输入参数：要查看的用户的id（不是用户自己的id）
 * @输出参数：上次存储的时间
 * @返回值：void
 * @author：yinlinlin
 */
- (NSString *)getlastTimeWithUserId:(NSString *)user_id
{
    NSDictionary * dynamicDict = [BanBu_CommUtils getLocalData:DynamicKey];
    if ([dynamicDict valueForKey:user_id])
    {
        return [[dynamicDict valueForKey:user_id] valueForKey:@"lasttime"];
    }
    else
    {
        return @"";
    }
}

/**
 *	@brief	导航控制器右按钮
 */
-(void)buildMoreButton
{
    moreActionBtn=[[BanBu_NavButton alloc] initWithButtonType:UIButtonCreatTypeNormal];
    moreActionBtn.position = ButtonPositionRight;
    moreActionBtn.frame=CGRectMake(280, 7, 30, 30);
    [moreActionBtn addTarget:self action:@selector(moreFunction:) forControlEvents:UIControlEventTouchUpInside];
    [moreActionBtn setBackgroundImage:[UIImage imageNamed:@"moreFunction.png"] forState:UIControlStateNormal];
    
    [self.navigationController.navigationBar addSubview:moreActionBtn];
//    self.navigationItem.rightBarButtonItem=[[[UIBarButtonItem alloc]initWithCustomView:moreActionBtn]autorelease];
//    [moreActionBtn release];
}

/**
 *	@brief	更多功能  添加关注  开始对话 拉黑 等等
 */
- (void)moreFunction:(UIButton *)sender
{ NSLog(@"%f",M_PI_4);
    
    

    int i = 1;
    if(moreFucView&&moreFucView.ishide == NO)
    {
        i = 1;
        [self hideFunctionView];
    }
    else
    {
        i = -1;
        [self showFunctionView];
    }
//    [UIView animateWithDuration:0.3 animations:^{
//        CGAffineTransform transform = moreActionBtn.transform;
//        transform = CGAffineTransformRotate(transform, M_PI_4 * i);
//        moreActionBtn.transform = transform;
//    }];
}
-(void)gochat
{
    BanBu_ChatViewController *chat = nil;
    for(UIViewController *vc in [self.navigationController viewControllers])
        if([vc isKindOfClass:[BanBu_ChatViewController class]])
        {
            chat = (BanBu_ChatViewController *)vc;
            
            //                NSLog(@"%@ %@",MyAppDataManager.chatuid,[_profile valueForKey:@"userid"]);
            if(![MyAppDataManager.chatuid isEqual:[_profileDic valueForKey:@"userid"]])
            {
                NSMutableArray *arr = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
                [arr removeObject:chat];
                self.navigationController.viewControllers = arr;
                chat = nil;
            }
            break;
            
        }
    if(chat)
    {
        [MyAppDataManager readTalkList:[_profileDic valueForKey:@"userid"] WithNumber:MyAppDataManager.dialogs.count];
        
        chat.smileViewBackup = MyAppDataManager.smileViewBackup;
        [self.navigationController popToViewController:chat animated:YES];
    }
    else
    {
        [MyAppDataManager readTalkList:[_profileDic valueForKey:@"userid"] WithNumber:5];
        
        chat = [[BanBu_ChatViewController alloc] initWithPeopleProfile:_profileDic];
        chat.smileViewBackup = MyAppDataManager.smileViewBackup;
        [self.navigationController pushViewController:chat animated:YES];
        [chat release];
    }
    
}
- (BOOL)isSelf
{
    return [[_profileDic valueForKey:@"userid"] isEqualToString:MyAppDataManager.useruid];
}
/**
 *	@brief	显示更多功能too把人
 */
-(void)showFunctionView
{
  
    if(!moreFucView)
    {
        zhezhaoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
        zhezhaoView.alpha = 0;
        zhezhaoView.backgroundColor = [UIColor blackColor];
        self.tableView.superview.backgroundColor = [UIColor clearColor];

        [self.tableView.superview addSubview:zhezhaoView];
        [zhezhaoView release];
        UITapGestureRecognizer *ges = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideFunctionView)];
        [zhezhaoView addGestureRecognizer:ges];
        [ges release];
        
        if([self isSelf])
        {
            moreFucView = [BanBu_FuncView instanceViewSelf];
            [moreFucView initViewSelf];
            moreFucView.frame = FUNCTIONVIEW_HIDE;
            moreFucView.ishide = YES;
            self.tableView.superview.backgroundColor = [UIColor clearColor];
            [self.tableView.superview addSubview:moreFucView];
        }
        else
        {
            moreFucView = [BanBu_FuncView instanceView];
            [moreFucView initDataWithLinkUserid:[_profileDic valueForKey:@"userid"]];
            moreFucView.personData = self;
            moreFucView.frame = FUNCTIONVIEW_HIDE;
            moreFucView.ishide = YES;
            self.tableView.superview.backgroundColor = [UIColor clearColor];
            [self.tableView.superview addSubview:moreFucView];
        }

    }
    zhezhaoView.hidden = NO;
    if(!moreFucView.ishide) { return; }
    
    
    
    [UIView animateWithDuration:0.3 animations:^{
        self.tableView.scrollEnabled = NO;
        moreFucView.frame = FUNCTIONVIEW_SHOW;
        moreFucView.ishide = NO;
        zhezhaoView.alpha = 0.6;
    }];
    
    __block BanBu_FuncView *func = moreFucView;
    __block BanBu_PersonDataViewController *bself = self;
    __block NSDictionary *d = _profileDic;
    //设置动态插件
    [func setGotoPlugSetting:^(UIButton *sender) {

        BanBu_PluginViewController *plugin = [[BanBu_PluginViewController alloc] init];
        plugin.title = NSLocalizedString(@"plasSet", nil);
        plugin.currentURL = [[[d valueForKey:@"spaceset"] valueForKey:@"space_json"] valueForKey:KEY_PICTURE];
        [bself.navigationController pushViewController:plugin animated:YES];
        [plugin release];
    }];
    //设置语音
    [func setGotoVoiceSetting:^(UIButton *sender) {
        BanBu_Voice_ViewController *voiceSetting = [[BanBu_Voice_ViewController alloc] init];
        voiceSetting.title = NSLocalizedString(@"voiceSet", nil);
        [bself.navigationController pushViewController:voiceSetting animated:YES];
        [voiceSetting release];
    }];    
    [func setStartChatReturn:^(UIButton *sender,BOOL succeed) {
        [bself hideFunctionView];
        [bself gochat];
    }];
    [func setAddlinkReturn:^(UIButton *sender,BOOL succeed,BOOL linked) {
        
        [bself hideFunctionView];
    }];
    
    [func setPullBlackReturn:^(UIButton *sender,BOOL succeed) {
        [bself hideFunctionView];
    }];
    [func setPullBlackAndReportReturn:^(UIButton *sender,BOOL succeed) {
        [bself hideFunctionView];
//        [[NSNotificationCenter  defaultCenter]postNotificationName:@"pullBlackReport" object:nil];

    }];
    [UIView animateWithDuration:0.3 animations:^{
        CGAffineTransform transform = moreActionBtn.transform;
        transform = CGAffineTransformRotate(transform, M_PI_4 * -1);
        moreActionBtn.transform = transform;
    }];
}

-(void)hideFunctionView
{
    if(moreFucView.ishide||!moreFucView) { return; }
    moreFucView.ishide = YES;
    [self.tableView.superview addSubview:moreFucView];
    [UIView animateWithDuration:0.3 animations:^{
        self.tableView.scrollEnabled = YES;
        zhezhaoView.alpha = 0;
        moreFucView.frame = FUNCTIONVIEW_HIDE;
    }];
    [UIView animateWithDuration:0.3 animations:^{
        CGAffineTransform transform = moreActionBtn.transform;
        transform = CGAffineTransformRotate(transform, M_PI_4 * 1);
        moreActionBtn.transform = transform;
    }];
}

- (void)banBu_LocationManager:(BanBu_LocationManager *)manager didGetLocation:(CLLocationCoordinate2D)coordinate success:(BOOL)success
{
    if(success)
    {
        [self getPosition];
        AppLocationManager.delegate = nil;
    }
    else
    {
        [self getPosition];
        AppLocationManager.delegate = nil;
    }
}

/**
 *	@brief	获取我的经纬度
 */

#pragma mark - 根据经纬度开始获取位置信息
-(void)getPosition
{
    if([self isSelf])
    {
        CLLocation *loc = [[CLLocation alloc] initWithLatitude:AppLocationManager.curLocation.latitude longitude:AppLocationManager.curLocation.longitude];
        [AppComManager getBanBuPosition:loc delegate:self];
    }
    else
    {
        NSString *plong = [_profileDic valueForKey:@"poslong"];
        NSString *plat  = [_profileDic valueForKey:@"poslat"];
        if([[_profileDic valueForKey:@"hideme"] isEqualToString:@"s"])
        {
            [self updateTitleWithString:NSLocalizedString(@"hide", nil)];
            return;
            
        }
         if(plong.length&&plat.length)
         {
             CLLocation *loc = [[CLLocation alloc] initWithLatitude:[plat floatValue]/1000000 longitude:[plong floatValue]/1000000];
             [AppComManager getBanBuPosition:loc delegate:self];
             [loc release];
         }
        else
        {
            [self updateTitleWithString:NSLocalizedString(@"noLocationInfo", nil)];

        }
    }
    
}

/**
 *	@brief	刷新title
 *
 *	@param 	_info 	title String
 */
- (void)updateTitleWithString:(NSString *)_info
{
    _titleView.name =  [MyAppDataManager IsInternationalLanguage:[_profileDic valueForKey:@"pname"]];
    self.titleView.position = _info;
}

#pragma mark - 开始获取位置信息
-(void)startGetMyPostitionInfo
{
    [self updateTitleWithString:NSLocalizedString(@"inTheLocation", nil)];
    if([self isSelf])
    {
        [AppLocationManager getMyLocation];
        AppLocationManager.delegate = self;
    }
    else
    {
        [self getPosition];
    }
}


/**
 *	@brief	headerView 点击的委托方法
 *
 *	@param 	_index 	点击的按钮index
 */
-(void)headerButtonDidPressWithIndex:(NSInteger)_index
{
    [self readyForLoadViewWithIndex:_index];
}
/**
 *	@brief	加载当前点击页 动态：0 相册：1 个人资料：2
 *
 *	@param 	_index 点击的按钮index
 */
-(void)readyForLoadViewWithIndex:(NSInteger)_index
{
    _currentIndex = _index;
    switch (_index) {
        case 0:
        {
            if(!broad)
            {
                broad = [[BanBu_BroadcastTVC alloc] init];
                [self addChildViewController:broad];

            }
            else
            {
                [broad loadingData];
            }
            
            broad.useridBroad = [_profileDic valueForKey:@"userid"];
            self.tableView = broad.tableView;

        }
            break;
        case 1:
        {
            if (!albumDetail)
            {
                albumDetail = [[BanBu_PersonAlbumDetailController alloc]initWithStyle:UITableViewStylePlain];
                albumDetail.user_id = [self.profileDic valueForKey:@"userid"];
                albumDetail.delegate = self;
            }
            self.tableView = albumDetail.tableView;
            [albumDetail getPhotoAlbumList];
        }
            break;
        case 2:
        {
            if([[_profileDic valueForKey:@"userid"] isEqualToString:MyAppDataManager.useruid])
            {
                if(!profile)
                {
                    profile = [[BanBu_ProfileDataController alloc] initWithProfile:self.profileDic];
                    [self addChildViewController:profile];

                }
                self.tableView = profile.tableView;
            }
            else
            {
                if(!peopleProfile)
                {
                    peopleProfile = [[BanBu_PeopleDataController alloc] initWithProfile:_profileDic displayType:1];
                    [self addChildViewController:peopleProfile];
                }
                [peopleProfile setProfile:_profileDic];
                self.tableView = peopleProfile.tableView;
            }

        }
            break;
        default:
            break;
    }

    
}

/**
 *	@brief	重写tableView set方法 来每次更换table都设置其header为本页的headerView
 *
 *	@param 	tableView
 */
-(void)setTableView:(UITableView *)tableView
{
    if(_tableView)
    {
        currentOffset = _tableView.contentOffset;
        _tableView.tableHeaderView = nil;
        [_tableView removeFromSuperview];
        _tableView = nil;
    }
    
    _tableView = tableView;
    if(tableView)
    {
        if(_tableView) { [self.view addSubview:_tableView]; }
        _tableView.tableHeaderView = headerView;
        _tableView.contentOffset = currentOffset;
    }
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

/**
 *	@brief	界面调整
 */
-(void)viewWillLayoutSubviews

{

    _tableView.frame = CGRectMake(0, 0, 320, __MainScreen_Height-44);
    headerView.frame = CGRectMake(0, 0, 320, 325);
    //将雪花的view提到最前面
    for(BanBu_SnowFall *snow in self.view.subviews)
    {
        if([snow isKindOfClass:[BanBu_SnowFall class]])
        {
            [self.view bringSubviewToFront:snow];
        }
    }
}

@end
